﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dao.RepositoryBase
{
    public interface IRepository<T> where T : class
    {
        /// <summary>
        /// 通过主键返回对象
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        T Get(object id);

        /// <summary>
        /// 保存对象
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns></returns>
        object Save(T model);

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="model">实体</param>
        void Update(T model);

        /// <summary>
        /// 保存或更新对象
        /// </summary>
        /// <param name="model">实体</param>
        void SaveOrUpdate(T model);

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="model">实体</param>
        void Delete(T model);

        /// <summary>
        /// 获取所有记录
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetAll();

        /// <summary>
        /// 获取分页集合
        /// </summary>
        /// <param name="firstResult">开始记录</param>
        /// <param name="maxResult">行数</param>
        /// <returns></returns>
        IQueryable<T> GetPageList(int firstResult, int maxResult);

        IQueryable<T> FindPageList(System.Reflection.PropertyInfo sort, string dir, int firstResult, int maxResult);

        IQueryable<T> FindPageList(out long total, System.Reflection.PropertyInfo sort, string dir, int firstResult, int maxResult);
    }
}
